//
//  LoginViewController.m
//  didacar
//
//  Created by imac on 15/12/5.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginNextStepViewController.h"
#import "UIImageView+WebCache.h"
#import "SVProgressHUD.h"
#import "UserViewModel.h"
#import "SmsCodeModel.h"
#import "MLInputDodger.h"
@interface LoginViewController ()
@property (strong, nonatomic) IBOutlet UITextField *textField;
- (IBAction)nextStepAction:(UIButton *)sender;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *view_layout_top;
@property (strong, nonatomic) IBOutlet UIView *contentView;
@property (strong, nonatomic) UserViewModel *userViewModel;
@property (weak, nonatomic) IBOutlet UIImageView *bannerImg;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.userViewModel = [[UserViewModel alloc ] init];
    [CommoneTools changeConstraintView:self.bannerImg constraintHeight:GTFixHeightFloat(137)];
    self.textField.leftView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 10, 10)];
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    self.textField.layer.borderColor = GLOBLE_GRAY_COLOR_1.CGColor;
    self.textField.layer.cornerRadius = 6;
    self.textField.layer.masksToBounds= YES;
    self.textField.layer.borderWidth = 0.45;
    

    [self setLeftCloseBtnItem];
}

//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//    
//    if (MOBILEMODEL_4S) {
//        WEAKSELF
//        [UIView animateWithDuration:0.2 animations:^{
//            weakSelf.view_layout_top.constant = - 50;
//            [weakSelf.contentView layoutIfNeeded];
//        }];
//    }
//    
//    return YES;
//}
//
//- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
//    
//    if (MOBILEMODEL_4S) {
//        WEAKSELF
//        [UIView animateWithDuration:0.2 animations:^{
//            weakSelf.view_layout_top.constant = 0;
//            [weakSelf.contentView layoutIfNeeded];
//        }];
//        
//    }
//    return YES;
//}

-(void)viewDidAppear:(BOOL)animated{
    [self.textField becomeFirstResponder];
    [super viewDidAppear:animated];
    self.view.shiftHeightAsDodgeViewForMLInputDodger = 44.0f+5.0f;
    [self.view registerAsDodgeViewForMLInputDodger];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


- (IBAction)nextStepAction:(UIButton *)sender {
    [self.textField resignFirstResponder];
    if ([CommoneTools isPhoneNumber:self.textField.text]) {
        
        self.userViewModel.mobile = self.textField.text;
        self.userViewModel.smsCode = @"111111";
        [self.userViewModel login:^(NSInteger resultType, id data, NSString *errorMsg) {
            if (resultType == 1) {
                [self dismissViewControllerAnimated:YES completion:^{
                    
                }];
            }else{
                [SVProgressHUD showErrorWithStatus:errorMsg];
            }
        }];
        
//
//        WEAKSELF
//        [self.userViewModel sendSmsCode:^(NSInteger resultType, id data, NSString *errorMsg) {
//            
//            if (resultType == 1) {
//                LoginNextStepViewController *loginNextStep = [weakSelf.storyboard instantiateViewControllerWithIdentifier:@"LoginNextStepViewController"];
//                loginNextStep.mobile = weakSelf.textField.text;
//           
//                [weakSelf.navigationController pushViewController:loginNextStep animated:YES];
//            }else{
//                   [SVProgressHUD showErrorWithStatus:errorMsg];
//            }
//        }];
    
    }else{
        [SVProgressHUD showErrorWithStatus:@"手机号错误"];
    }
}
@end
